package com.jiangyao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiangyao.common.ApiResult;
import com.jiangyao.model.dto.*;
import com.jiangyao.model.vo.*;
import com.jiangyao.service.PublicSubjectService;
import com.jiangyao.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lijing
 * @create 2020/8/12
 */

@RestController
@RequestMapping("/publicSubject")
@Api(tags = "公开课程相关接口")
public class PublicSubjectController extends BaseController{



    @Autowired
    private PublicSubjectService publicSubjectService;
    @Autowired
    private QuestionService questionService;

    @PostMapping("getSubjectInfo")
    @ApiOperation(value = "获取用户学习课程的信息")
    public ApiResult<PublicSubjectVo> getSubjectInfo (@RequestBody PublicSubjectDto publicSubjectDto){

        return ApiResult.success(publicSubjectService.getSubjectInfo(publicSubjectDto));
    }

    @PostMapping("getDirectory")
    @ApiOperation(value="获取当前用户学习的课程目录完成情况")
    public ApiResult<SChapterVo> getDirectory(@RequestBody PublicSubjectDto publicSubjectDto){
        return ApiResult.success(publicSubjectService.getPublicChapterCourseware(publicSubjectDto));
    }

    @PostMapping("getQuestionsList")
    @ApiOperation("课程下的试题列表")
    public ApiResult<PublicChapterQuestionVo> getQuestionsList(@RequestBody PublicSubjectDto publicSubjectDto){
        return ApiResult.success(publicSubjectService.getQuestionsList(publicSubjectDto));
    }


    @PostMapping("getCommentList")
    @ApiOperation("课程评价列表")
    public ApiResult<Page<EvaluationVo>> getCommentList(@RequestBody SubjectListPageDto subjectListPageDto){
        return ApiResult.success(publicSubjectService.getCommentList(subjectListPageDto));
    }

    @PostMapping("getCoursewareInfo")
    @ApiOperation("当前用户点击课件学习详情")
    public ApiResult<ChapterCoursewareVo> getCoursewareInfo(@RequestBody PublicCoursewareDTO coursewareDTO){
        return ApiResult.success(publicSubjectService.getPublicCoursewareInfo(coursewareDTO));
    }

    @PostMapping("getCoursewareList")
    @ApiOperation("课件学习页面对应的课件列表")
    public ApiResult<SChapterCoursewareVo> getCoursewareList(@RequestBody PublicCoursewareDTO coursewareDTO){
        return ApiResult.success(publicSubjectService.getPublicCoursewareList(coursewareDTO));
    }

    @PostMapping("saveCourseware")
    @ApiOperation("保存课件学习的情况")
    public ApiResult<Boolean> saveCourseware(@Validated({StudyCoursewareDto.Add.class})@RequestBody PublicStudyCoursewareDto studyCoursewareDto){
        return ApiResult.success(publicSubjectService.saveCourseware(studyCoursewareDto));
    }


    @PostMapping("saveComment")
    @ApiOperation("保存评论")
    public ApiResult<Boolean> saveComment(@RequestBody PublicEvaluationDto evaluationDto){
        return ApiResult.success(publicSubjectService.saveComment(evaluationDto));
    }

    @PostMapping("saveReply")
    @ApiOperation("保存回复")
    public ApiResult<Boolean> saveReply(@RequestBody PublicEvaluationDto evaluationDto){
        return ApiResult.success(publicSubjectService.saveReply(evaluationDto));
    }

    @PostMapping("getLike")
    @ApiOperation("查询对课程是否点赞")
    public ApiResult<Boolean> getLike(@RequestBody PublicSubjectDto subjectDto){
        return ApiResult.success(publicSubjectService.getLike(subjectDto));
    }

    @ApiOperation("提交学习课程的面试试题")
    @PostMapping("/submitCourseQuestion")
    public ApiResult<SubmitQuestionVo> submitCourseQuestion(@Validated @RequestBody SubmitPublicCourseQuestionDTO submitCourseQuestionDTO){

        return ApiResult.success(questionService.submitPublicCourseQuestion(submitCourseQuestionDTO));
    }

    @ApiOperation("提交课程报名")
    @PostMapping("submitApply")
    public ApiResult<Boolean> submitApply(@RequestBody PublicSubjectDto subjectDto){
        return ApiResult.success(publicSubjectService.saveApply(subjectDto));
    }


}
